package com.example.springmvc.controller;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


//@RequestMapping支持get和post请求 url访问是get请求
//我们可以通过修改method使@RequestMapping只支持其中一种方法
//method = RequestMethod.POST     RequestMethod是枚举
@Controller  //使用该注解进行前后端交互
@RequestMapping("/test")//一级路径
@ResponseBody//返回一个非静态页面
public class TestController {

    @RequestMapping("/sayhi")//二级路径
    public String sayHi() {
        return "hello sayHi";
    }

    // 如果是post请求 那么网页就访问不到了
    @RequestMapping(method = RequestMethod.POST,value = "/sayhi2")//二级路径
    public String sayHi2() {
        return "hello sayHi2";
    }

    // get请求网页可以访问到
    @RequestMapping(method = RequestMethod.GET,value = "/sayhi3")//二级路径
    public String sayHi3() {
        return "hello sayHi3";
    }

//    @RequestMapping也分离出两种方法 getMapping和postMapping
    @GetMapping(value = "/sayhi4")
    public String sayHi4() {
        return "hello sayHi4";
    }

    @PostMapping("/sayhi5")
    public String sayHi5() {
        return "hello sayHi5";
    }


    // 验证我们运行哪个配置文件
    @Value("${img.path}")
    private String path;
    @GetMapping(value = "/sayhi6")
    public String sayHi6() {
        return "hello sayHi6  " + path;
    }
}
